package edu.jabs.imageViewer.interfaz;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

/**
 * Binarization Threshold buttons Pane
 */
public class ThresholdButtonsPane extends JPanel implements ActionListener
{
    //-----------------------------------------------------------------
    // Constants
    //-----------------------------------------------------------------

    /**
     * Accept
     */
    public final static String ACCEPT = "accept";

    /**
     * Cancel
     */
    public final static String CANCEL = "cancel";

    //-----------------------------------------------------------------
    // GUI Fields
    //-----------------------------------------------------------------

    /**
     * Accept Button
     */
    private JButton butAccept;

    /**
     * Cancel Button
     */
    private JButton butCancel;

    //-----------------------------------------------------------------
    // Fields
    //-----------------------------------------------------------------

    /**
     * Dialogue that owns this panel
     */
    private ThresholdBinarizationDialogue dialogue;

    //-----------------------------------------------------------------
    // Constructors
    //-----------------------------------------------------------------

    /**
     * It builds the binarization threshold buttons pane
     * @param theDialogue Dialogue that owns this panel. theDialogue != null.
     */
    public ThresholdButtonsPane( ThresholdBinarizationDialogue theDialogue )
    {
        //The dialogue reference is saved
        dialogue = theDialogue;

        //The layout is set
        setLayout( new GridLayout( 1, 2 ) );

        //The graphical elements are initilized
        butAccept = new JButton( "Accept" );
        butAccept.setActionCommand( ACCEPT );
        butAccept.addActionListener( this );

        butCancel = new JButton( "Cancel" );
        butCancel.setActionCommand( CANCEL );
        butCancel.addActionListener( this );

        //The elements are added
        add( butAccept );
        add( butCancel );
    }

    //-----------------------------------------------------------------
    // Methods
    //-----------------------------------------------------------------

    /**
     * It executes the action events
     * @param event Event generated by the action. event != null.
     */
    public void actionPerformed( ActionEvent event )
    {
        String command = event.getActionCommand( );
        if( command.equals( ACCEPT ) )
        {
            dialogue.accept( );
        }
        if( command.equals( CANCEL ) )
        {
            dialogue.cancel( );
        }
    }
}